home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2855 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.3 KB  |  65 lines

  1. Path: shanghai.netgen.com!new-york!erichard
  2. From: Eric Richard <erichard@netgen.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: G++ and global const variable definitions
  5. Date: Fri, 19 Jan 1996 14:39:16 -0500
  6. Organization: net.Genesis Corp.
  7. Message-ID: <Pine.SOL.3.91.960119141858.13188C-100000@new-york>
  8. NNTP-Posting-Host: new-york.netgen.com
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11. X-Sender: erichard@new-york
  12.  
  13.  
  14. I have a C++ file that contains a single statement: a definition and
  15. initialization of a global constant variable.  It basically looks like this:
  16.  
  17. extern RWDBPhraseBook const RWDBInformixPhraseBook =
  18. {
  19.   "",                           //beginExprOperatorGroup,
  20.   "NoOp",                       //operatorNoOp,
  21.   ...
  22. };
  23.  
  24. When I compile the file and 'nm' the resulting object file, I 
  25. only get this:
  26.  
  27. [Index]   Value      Size    Type  Bind  Other Shndx   Name
  28.  
  29. [3]     |         0|       0|SECT |LOCL |0    |2      |infphras.o:
  30. [2]     |         0|       0|NOTY |LOCL |0    |2      |infphras.o:gcc2_compiled.
  31. [1]     |         0|       0|FILE |LOCL |0    |ABS    |infphras.o:infphras.cpp
  32.  
  33. If I take out the "extern" and "const", the variable's symbol shows
  34. up:
  35.  
  36. [4]     |         0|       0|SECT |LOCL |0    |4      |infphras.o:
  37. [2]     |         0|       0|SECT |LOCL |0    |3      |infphras.o:
  38. [5]     |         0|       0|SECT |LOCL |0    |2      |infphras.o:
  39. [6]     |         0|     892|OBJT |GLOB |0    |4      |infphras.o:RWDBInformixPhraseBook
  40. [3]     |         0|       0|NOTY |LOCL |0    |2      |infphras.o:gcc2_compiled.
  41. [1]     |         0|       0|FILE |LOCL |0    |ABS    |infphras.o:infphras.cpp
  42.  
  43.  
  44. According to "Advanced C++ Programming Styles and Idioms":
  45.  
  46.   "Constants may be shared across source files by declaring them
  47.   extern.  These declarations can be placed in a commonly included
  48.   header file ... and a SINGLE definition of the value placed in 
  49.   a convenient program source file:
  50.  
  51.   ...
  52.   extern const double e = exp( 1.0 );
  53.  
  54. Any clue what is up here?
  55.  
  56.                                  -Eric Richard
  57.  
  58. Eric Richard ----------------------------------- voice: (617) 577-9800
  59. net.Genesis                                        fax: (617) 577-9850
  60. 68 Rogers St                                       erichard@netgen.com 
  61. Cambridge, MA 02142 --------------------------- http://www.netgen.com/
  62.  
  63.  
  64.  
  65.